package Homework.Three;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        T1User p = new T1User();
        System.out.println("请输入name:");
        p.name = scan.next();
        String reg = "^[0-9a-zA-Z_]{1,32}";
        if (p.name.matches(reg)){
            System.out.println("命名成功");
        }else {
            System.out.println("请重新命名，只能包含数字，字母，下划线，并且只有32位");
            p.name = scan.next();
        }
        System.out.println("请输入pwd:");
        p.pwd = scan.next();
        System.out.println("请输入age:");
        p.age = scan.nextInt();
        System.out.println("请输入nick:");
        p.nick = scan.next();
        try{
            p.nick.equals(null);
            p.name.equals(null);
            p.pwd.equals(null);
        }catch (NullPointerException e){
            System.out.println("输入了空的信息，请重新输入");
        }
        FileOutputStream fos = new FileOutputStream(p.name+".obj");
        ObjectOutputStream obs = new ObjectOutputStream(fos);
        obs.writeObject(p);
        fos.close();
        obs.close();
    }
}
